package com.tom.architect.day17.simple4;

public class Client {

    public static void main(String[] args) {
        User user = new User();
        user.age = 23;
        user.userName = "Tom";
        user.userAddress = new User.Address("福南", "长沙");

        // 浅拷贝:姓名还是各自的，但是内部的对象还是原来的。
        // 累的类对象实例，是没有靠背的，还是共用一份。用的是同一个实例。
        try {
            User copyUser = user.clone();
            System.out.println("name:" + user.userName + " addr:" + user.userAddress.addressName);
            System.out.println("name:" + copyUser.userName + " addr:" + copyUser.userAddress.addressName);
            copyUser.userAddress.addressName = "深圳珠海";
            copyUser.userName = "xiaoli";
            System.out.println("name:" + user.userName + " addr:" + user.userAddress.addressName);
            System.out.println("name:" + copyUser.userName + " addr:" + copyUser.userAddress.addressName);
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        System.out.println("-----------------");

    }
}
